package com.wn.pettyloan.controller;

import com.wn.pettyloan.dto.EmpDto;
import com.wn.pettyloan.entity.Emp;
import com.wn.pettyloan.service.EmpService;
import com.wn.pettyloan.util.Result;
import com.wn.pettyloan.vo.EmpVo;
import com.wn.pettyloan.vo.RoleVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: pettyloan
 * @ClassName EmpController
 * @description:
 * @author: 韩旭
 * @create: 2022-12-09 17:19
 **/

@RestController
@RequestMapping("emp")
public class EmpController {
    @Resource
    private EmpService empService;


    @PostMapping("login")
    public Result empLogin(@RequestBody EmpDto empDto){
        EmpVo empVo = empService.empLogin(empDto);
        if (empVo != null) {
            return Result.ok().data("emp",empVo);
        }
        return Result.error("请输入正确的账号密码");
    }

    @GetMapping("quaryAll")
    public Result quaryAll(){
        List<Emp> empList = empService.selectAll();
        List<RoleVo>  roleByEmp = empService.selectRoleByEmp();
        return Result.ok().data("empList",empList).data("roleList",roleByEmp);
    }

    @GetMapping("{empId}")
    public Result quaryOne(@PathVariable Long empId){
        Emp emp = empService.selectByPrimaryKey(empId);
        return Result.ok().data("emp",emp);
    }

    @PutMapping()
    public Result quaryOne(@RequestBody Emp emp){
        empService.updateByPrimaryKeySelective(emp);
        return Result.ok();
    }

    @PostMapping()
    public Result addEmp(@RequestBody Emp emp){
        System.out.println(emp.getEmpCode());
        empService.insertSelective(emp);
        return Result.ok();
    }

}